﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EasyClass {
	public partial class StudentsStatusForm : Form {
		Controller controller;
		private Dictionary<string, Account> students;
		public StudentsStatusForm(Controller c) {
			InitializeComponent();

			controller = c;
			students = c.GetStudents();
			listView1.Columns.Add("Student ID", 100, HorizontalAlignment.Center);
			listView1.Columns.Add("Status", 60, HorizontalAlignment.Center);
			listView1.Columns.Add("Email", -2, HorizontalAlignment.Center);
			FreshListView();
		}

		private void FreshListView() {
			listView1.Items.Clear();
			this.listView1.BeginUpdate();  //suspend UI update
			foreach (Account account in students.Values) {
				ListViewItem lvi = new ListViewItem();
				lvi.Text = account.studentID;
				if (account.status == 0) {
					lvi.SubItems.Add("Off");
				} else {
					lvi.SubItems.Add("On");
				}
				lvi.SubItems.Add(account.email);
				listView1.Items.Add(lvi);
			}
			this.listView1.EndUpdate();  //recover UI
		}

		private void StudentsStatusForm_Load(object sender, EventArgs e) {

		}

		private void button1_Click(object sender, EventArgs e) {
			for (int i = 0; i < listView1.SelectedItems.Count; ++i)
				students.Remove(listView1.SelectedItems[i].Text);
			FreshListView();
		}

		private void button2_Click(object sender, EventArgs e) {
			Close();
		}

		private void button3_Click(object sender, EventArgs e) {
			FreshListView();
		}
	}
}
